package com.usian.controller;

import com.usian.commom.pojo.User;
import com.usian.commom.vo.ResultCommonVo;
import com.usian.fegin.UserFegin;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @TODO:
 * @Author:baimu
 * @Date:2023 11 23 09 04
 **/

@RestController
@RequestMapping("/test/user")
@Slf4j
@RefreshScope
public class TestController {


    @Value("${my.name}")
    String myName;


    @RequestMapping("/testName")
    public String testName(){
        log.info("name:{}",myName);
        return myName;
    }


    @Autowired
    UserFegin userFegin;


    @RequestMapping("/findAllUser")
    public List<User> findAllUser(){
       return  userFegin.findAllUser();
    }

    @GetMapping("/findUserById")
    public User findUserById(@RequestParam Long id){
        return userFegin.findUserById(id);
    }

    @GetMapping("/findUserByUsernameANdage")
    public List<User> findUserByUsernameANdage(String username,Integer age){
        return userFegin.findUserByUsernameANdage(username,age);
    }

    @PostMapping("/saveUser")
    public ResultCommonVo saveUser(@RequestBody User user){

        return userFegin.saveUser(user);
    }

    @PostMapping("/findUserPage")
    public ResultCommonVo findUserPage(@RequestBody User user
            , @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum
            , @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        return userFegin.findUserPage(user,pageNum,pageSize);
    }
}
